package genedit.gui.propertyDialogs;

import genedit.gui.GMainFrame;
import genedit.gui.exceptions.RequiredFieldException;
import genedit.gui.propertyDialogs.AbstractDialog.StanjeDijaloga;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class PanelDetailParameter  extends AbstractPanelDetail {
	

	
	private JLabel lblType;
	private JTextField txtType;
	
	private JLabel lblName;
	private JTextField txtName;
	
	
	public PanelDetailParameter(StanjeDijaloga mode) {
		
		setLayout(new BorderLayout());

		Dimension lblDimension = new Dimension(150,20);
		
		Box boxCentar = new Box(BoxLayout.Y_AXIS);
		
		
		JPanel panType = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblType = new JLabel(GMainFrame.getInstance().getResourceBundle().getString("lblType"));
		lblType.setPreferredSize(lblDimension);
		txtType = new JTextField(10);
		txtType.setEnabled(mode != StanjeDijaloga.BROWSE);
		panType.add(lblType);
		panType.add(txtType);
		boxCentar.add(panType);
		

		JPanel panName = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblName = new JLabel(GMainFrame.getInstance().getResourceBundle().getString("lblName"));
		lblName.setPreferredSize(lblDimension);
		txtName = new JTextField(10);
		txtName.setEnabled((mode != StanjeDijaloga.BROWSE));
		panName.add(lblName);
		panName.add(txtName);
		boxCentar.add(panName);

		add(boxCentar,BorderLayout.CENTER);
		
	}
	





	public JTextField getTxtType() {
		return txtType;
	}





	public void setTxtType(JTextField txtType) {
		this.txtType = txtType;
	}





	public JTextField getTxtName() {
		return txtName;
	}





	public void setTxtName(JTextField txtName) {
		this.txtName = txtName;
	}





	public void proveriIspravnostPodataka() throws RequiredFieldException {
		
		if (txtType.getText().trim().equals("")) {
			txtType.setBackground(Color.RED);
			//ok = false;
			txtType.addKeyListener(new KeyListener() {
				
				@Override
				public void keyTyped(KeyEvent e) {
					
					
				}
				
				@Override
				public void keyReleased(KeyEvent e) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void keyPressed(KeyEvent e) {
					if (e.isActionKey() || e.getKeyCode()==KeyEvent.VK_ENTER || e.getKeyCode()==KeyEvent.VK_BACK_SPACE)
						return;
					
					else
						txtType.setBackground(Color.WHITE);
			//		ok = true;
					
				}
			});
			RequiredFieldException rfe = new RequiredFieldException(
					);
			throw rfe;
		}
		
		if (txtName.getText().trim().equals("")) {
			txtName.setBackground(Color.RED);
		//	ok = false;
			txtName.addKeyListener(new KeyListener() {
				
				@Override
				public void keyTyped(KeyEvent e) {
					
					
				}
				
				@Override
				public void keyReleased(KeyEvent e) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void keyPressed(KeyEvent e) {
					if (e.isActionKey() || e.getKeyCode()==KeyEvent.VK_ENTER || e.getKeyCode()==KeyEvent.VK_BACK_SPACE)
						return;
					
					else
						txtName.setBackground(Color.WHITE);
			//		ok = true;
					
				}
			});
			RequiredFieldException rfe = new RequiredFieldException(
					);
			throw rfe;
		}
		
	
		//return ok;
	}


}
